package com.j2110.service;

import com.j2110.dao.EmpDao;
import com.j2110.pojo.Emp;
import com.j2110.utils.Result;

import java.util.List;

public class EmpService {
    private final EmpDao dao = new EmpDao();


    public List<Emp> getEmps(){
        return dao.query();
    }

    public Result execute(Emp stu){
        int execute = dao.execute(stu);
        if (execute > 0){
           return Result.me();
        }else {
            return Result.me(false);
        }
    }

    public Result delete(String id) {
        int delete = dao.delete(id);
        if (delete > 0){
            return Result.me();
        }else {
            return Result.me(false);
        }
    }

    public Result update(Emp stu) {
        int update = dao.update(stu);
        if (update > 0){
            return Result.me();
        }else {
            return Result.me(false);
        }
    }

    public Result query(String id) {
        List<Emp> list = dao.queryById(id);
        if (list != null && list.size() > 0){
            return Result.me(list);
        }else {
            return Result.me(false);
        }
    }

    public Result queryByName(String name) {
        List<Emp> list = dao.queryByName(name);
        if (list != null && list.size() > 0){
            return Result.me(list);
        }else {
            return Result.me(false);
        }
    }
}
